import java.util.ArrayList;

import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Geometry;
import com.jme.scene.Line;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.shape.Sphere.TextureMode;

/*
 * A Node
 */
public class ANode {

	//the location of the node x/z/y
	private Vector3f location = new Vector3f(0.0f,0.0f,0.0f);
	//list of locations
	private ArrayList<Vector3f> locations = new ArrayList<Vector3f>();
	//a list of the node representations on plane
	//private ArrayList<Sphere> nodeLocations = new ArrayList<Sphere>();
	//a scenegraph node to link all nodes too
	private Node nodes = new Node("Nodes");
	//list of links shownig movement
	private ArrayList<Vector3f> links = new ArrayList<Vector3f>();
	
	public ANode()
	{
		//the shape of a node
		Sphere aNode = new Sphere("node");
		int numberNodes = getNumberOfNodes();
		aNode.setDefaultColor(ColorRGBA.blue.clone());
		this.setLocation(0f,0f,0f);
		aNode.updateGeometry(getLocation(numberNodes), 30, 30, 0.3f);
		nodes.attachChild(aNode);
	}
	
	public ANode(Vector3f startPosition)
	{
		Sphere aNode = new Sphere("node");
		int numberNodes = getNumberOfNodes();
		aNode.setDefaultColor(ColorRGBA.blue.clone());
		this.setLocation(startPosition);
		aNode.updateGeometry(getLocation(numberNodes), 30, 30, 0.3f);
		nodes.attachChild(aNode);
	}
	
	public void addNodeLocation(Vector3f loc)
	{
		Sphere aNode = new Sphere("node");
		int numberNodes = getNumberOfNodes();
		aNode.setDefaultColor(ColorRGBA.blue.clone());
		this.setLocation(loc);
		aNode.updateGeometry(getLocation(numberNodes), 30, 30, 0.3f);
		nodes.attachChild(aNode);
		//link from previous node to itself
		links.add(new Vector3f(this.getLocation(numberNodes-1)));	
		links.add(new Vector3f(loc));
		Geometry link = new Line("Link Line", links.toArray(new Vector3f[] {}), null, null, null);
		link.getDefaultColor().set(ColorRGBA.blue);
		nodes.attachChild(link);


	}
	
	public void setLocation(float addX, float addY, float addZ)
	{
		location.set(addX, addY, addZ);

	}
	
	public int getNumberOfNodes()
	{
		return locations.size();
	}
	
	public void setLocation(Vector3f loc)
	{
			locations.add(loc);
	}
	
	public Vector3f getLocation(int nodeNumber)
	{
		return locations.get(nodeNumber);
	}
	
	public Node getNode()
	{
		return nodes;
	}
	
	public void setColour()
	{
		//aNode.setTextureMode(null);
	}
}
